//
//  CCKPublishModel.m
//  budejieMe
//
//  Created by 韦恺 on 16/8/26.
//  Copyright © 2016年 SuperJJ. All rights reserved.
//

#import "CCKPublishModel.h"
#import <AFNetworking.h>

@implementation CCKPublishModel

+ (void)downloadPublishDataWithUrl:(NSString *)url successBlock:(void (^)(NSArray *dataArr))successBlock failBlock:(void (^)(NSError *error))failBlock
{
    [[AFHTTPSessionManager manager] GET:url parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, NSDictionary *responseObject) {
        
        NSArray *array = responseObject[@"square_list"];
        NSMutableArray *arrM = [NSMutableArray arrayWithCapacity:array.count];
        
        [array enumerateObjectsUsingBlock:^(NSDictionary *obj, NSUInteger idx, BOOL * _Nonnull stop) {
            
            [arrM addObject:[CCKPublishModel publishWithDict:obj]];
        }];
        
        if (successBlock) {
            successBlock(arrM.copy);
        }
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        if (failBlock) {
            failBlock(error);
        }
        
    }];

}

- (void)setValue:(id)value forUndefinedKey:(NSString *)key
{
    
}

+ (instancetype)publishWithDict:(NSDictionary *)dict
{
    CCKPublishModel *model = [CCKPublishModel new];
    [model setValuesForKeysWithDictionary:dict];
    return model;
}

@end
